from ext import db

class RoleModel(db.Model):
    __tablename__ = 'role'
    id = db.Column(db.Integer, autoincrement=True,primary_key=True)
    name = db.Column(db.String(128), comment='权限')

class UserModel(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer,autoincrement=True,primary_key=True)
    name = db.Column(db.String(128),comment='用户名')
    account = db.Column(db.String(64),comment='账户')
    password = db.Column(db.String(156),comment='密码')
    gender = db.Column(db.String(8),default='男',comment='性别')
    age = db.Column(db.SmallInteger,comment='年龄')
    role_id = db.Column(db.Integer, db.ForeignKey("role.id"))  # 外键 (一对多)
    role = db.relationship("RoleModel", backref=db.backref('users'))



